<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<div class="right">
    <div class="location">
        <strong>当前位置:</strong>
        <span>密码修改页面</span>
    </div>
    <div class="supplierAdd">
        <form id="userForm" name="userForm" method="post"
              action="${pageContext.request.contextPath }/user/savePassword">
            <input type="hidden" name="id" value="${id}">
            <!--div的class 为error是验证错误，ok是验证成功-->
            <div class="info">${message}</div>
            <div class="">
                <label for="oldPassword">旧密码：</label>
                <input type="password" name="oldPassword" id="oldpassword" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="newPassword">新密码：</label>
                <input type="password" name="newPassword" id="newpassword" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="reNewPassword">确认新密码：</label>
                <input type="password" name="reNewPassword" id="rnewpassword" value="">
                <font color="red"></font>
            </div>
            <div class="supplierAddBtn">
                <!--<a href="#">保存</a>-->
                <input type="button" name="save" id="save" value="保存" class="input-button">
            </div>
        </form>
    </div>
</div>
</section>
<%@include file="/WEB-INF/jsp/common/foot.jsp" %>
<%--<script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/sysUser/updatePassword.js"></script>--%>
<script>

    $("#save").click(function () {
        var val1 = $("#newpassword").val();
        var val2 = $("#rnewpassword").val();
        if (val1 == val2 && val2 != "") {
            $.ajax({
                url: "${pageContext.request.contextPath}/system/updatePwd",
                data: {"newPwd": val1},
                dataType: "JSON",
                type: "GET",
                success: function (data) {
                    console.log(data)
                    if (data > 0) {
                        alert("修改成功");
                        location.href = "${pageContext.request.contextPath}/system/users"
                    } else {
                        alert("修改失败");
                    }
                }
            })
        } else {
            alert("两次密码不正确");
        }
    })

    $("#oldpassword").blur(function () {
        var putPwd = $(this);
        var oldPwd = $(this).val();
        if (oldPwd != "") {
            $.ajax({
                    url: "${pageContext.request.contextPath}/system/putterPwd",
                    data: {"oldPwd": oldPwd},
                    dataType: "JSON",
                    type: "POST",
                    success: function (data) {
                        console.log(data)
                        if (data == true) {
                            putPwd.next().text("密码正确").css("color", "green")
                        } else {
                            putPwd.next().text("密码错误").css("color", "red")
                        }
                    }
                }
            )

        }
    })
</script>